/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package factoryTotal;

import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.geom.Circle;
import org.newdawn.slick.geom.Rectangle;

/**
 *
 * @author wida46984148
 */
public class DisparoLaser extends Disparo {

    Image laser;
    Image laserExp;
    int cnt = 0;

    public DisparoLaser(float dany, Image laser, Image laserExp) {
        super(dany);
        this.laser = laser;
        this.laserExp = laserExp;
    }

    /**
     * Canvia la posicio del projectil
     * @param pX
     * @param pY
     */
    @Override
    public void posicion(float posX, float posY) {
        super.posicion(posX, posY);
        if (!(posY == 456 )){
            super.s = new Rectangle(posX, posY, laser.getWidth(), laser.getHeight());
        } else {
            super.s = new Rectangle(posX-100, posY, laserExp.getWidth(), laserExp.getHeight());
        }
    }

    /**
     * Rederitza el projectil
     * @param gc
     * @param g
     */
    @Override
    public void render(GameContainer gc, Graphics g) {
        if(!(pY == 456)){
            g.drawImage(laser, pX, pY);
        }else {
            posicion(pX, pY);
            g.drawImage(laserExp, pX -100, 456);
        }
    }

    /**
     * Copia el projectil
     * @return projectil clonat
     */
    @Override
    public Disparo copiarDisparo() {
        return new DisparoLaser(daño, laser, laserExp);
    }

    /**
     * Getter projectil clonat
     * @return projectil
     */
    public Disparo clonarDisparo() {
        Disparo p = (Disparo) copiarDisparo();
        p.posicion(pX, pY);
        return p;
    }

    /**
     * Genera impacte
     */
    public void impacto() {
        this.destruido = true;
    }

    public Image getLaser() {
        return laser;
    }

    @Override
    public void update(int delta) {
        if (!destruido) {
            if (pY <= 10) {
                pY = -11;
                pX = 1300;
            } else if(pY == 456){
                cnt++;
                pY = 456;
                if(cnt == 5) destruido = true;
                
            } else {
                pY += 9;
                s.setLocation(pX, pY);
            }
        } else {
            pY = 1300;
            pX = 1300;
        }
    }

}

